﻿namespace STLTypeVisualizer
{
	using System;
	using VisualGDBExpressions;

	internal class GccSetFilter : GccTreeFilter
	{
		static string[] textArray1 = new string[] { "std::set<", "std::multiset<" };
		public GccSetFilter() : base(textArray1)
		{
		}

		protected override IExpression CreateNodeExpression(IExpressionEvaluator evaluator, string treeNodeExpr, ref int idx)
		{
			// __cplusplus < 201103L的版本使用的是_M_value_field，之后的版本使用的_M_storage
			IExpression expr = evaluator.CreateExpression(treeNodeExpr + "->_M_value_field", false);
			if (expr == null)
			{
				string[] textArray1 = new string[] { "*((__typeof__(", treeNodeExpr, "->_M_valptr()))&(", treeNodeExpr, "->_M_storage->_M_storage))" };
				expr = evaluator.CreateExpression(string.Concat(textArray1), false);
			}
			if (expr == null)
			{
				return null;
			}
			int num = idx;
			idx = num + 1;
			StaticExpressionFilter filter1 = new StaticExpressionFilter(expr);
			filter1.ShortNameOverride = $"[{num}]";
			return filter1;
		}

		protected override string ExpandLabel =>
			"[展开以填充std::set]";
	}

	internal class ClangSetFilter : ClangTreeFilter
	{
		static string[] textArray1 = new string[] { "std::__1::set<", "std::__1::multiset<" };
		public ClangSetFilter() : base(textArray1)
		{
		}

		protected override IExpression CreateNodeExpression(IExpressionEvaluator evaluator, string treeNodeExpr, ref int idx)
		{
			IExpression expr = evaluator.CreateExpression(treeNodeExpr + "->__value_", false);
			if (expr == null)
			{
				return null;
			}
			int num = idx;
			idx = num + 1;
			StaticExpressionFilter filter1 = new StaticExpressionFilter(expr);
			filter1.ShortNameOverride = $"[{num}]";
			return filter1;
		}

		protected override string ExpandLabel =>
			"[展开以填充std::set]";
	}
}

